package cn.edu.scau.cmi.yangqing.factory;

import java.net.URL;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;

public class MyController implements Initializable {

	   @FXML
	   private Button myButton;

	   @FXML
	   private ChoiceBox<String> myChoiceBox;

	   @FXML
	   private ChoiceBox<String> myChoiceBox2;
	   @FXML
	   private TextField myTextField2;
	   public void initialize(URL location, ResourceBundle resources) {
	   }

	   public void showDateTime2(ActionEvent event) {
	       System.out.println("Button Clicked!");
	       System.out.println(myChoiceBox.getSelectionModel().getSelectedIndex());
	       
	       Integer checkboxIndex = myChoiceBox.getSelectionModel().getSelectedIndex();
	       Integer checkboxIndex2 = myChoiceBox2.getSelectionModel().getSelectedIndex();
	       Creator creator = null;
	       Insurance insurance =null;
	       switch (checkboxIndex2) {
				case 0:
					creator = new CreatorPICC();
					break;
				case 1:
					creator = new CreatorPingan();
					break;
				default:
					break;
		}
	       switch (checkboxIndex) {
			case 0:
			    insurance = creator.driverInsuranceFactory();
				break;
			case 1:
				insurance = creator.carInsuranceFactory();
				break;
			case 2:
				insurance = creator.personInsuranceFactory();
				break;
			case 3:
				insurance = creator.mutilInsuranceFactory();
				break;
			default:
				break;
		}
	       String output = insurance.getInsurance();
	       myTextField2.setText(output);
		/*
		 * //添加监听器监听checkbox的改变
		 * myChoiceBox.getSelectionModel().selectedIndexProperty().addListener( new
		 * ChangeListener<Number>() { Integer num = -1; Integer oldNum = -1; public void
		 * changed(ObservableValue<? extends Number> observable, Number oldValue, Number
		 * newValue) { oldNum = oldValue.intValue(); num = newValue.intValue();
		 * System.out.println(oldNum +"num = "+ num); } });
		 */ 
	   }
}
